local modname = ...
local M = {}
_G[modname] = M
package.loaded[modname] = M

local http = require("socket.http")
local json = require("ac.json")

M.urlresip="http://192.168.10.254/resip.php"
M.urlstatus="http://192.168.10.254/status.php"
M.urladopt="http://192.168.10.254/adopt.php"

function M.web_sync(status)
	local newstatus, err = http.request(M.urlstatus, status)
	if newstatus == nil then
		print("http request failed:" .. err);
		return nil
	end
	return json.decode(newstatus);
end

function M.web_adopt(status)
	local adoptstr, err = http.request(M.urladopt, status)
	if adoptstr == nil then
		print("http request failed:" .. err);
		return false
	end
	local adopt = tonumber(adoptstr);

	return (adopt and adopt > 0) and true or false
end

function M.web_resip()
	local ipoolstr, err = http.request(M.urlresip, status)
	if ipoolstr == nil then
		print("http request failed:" .. err);
		return false
	end
	return ipoolstr
end
